package com.zy.aiLocation.controller;

import org.dromara.x.file.storage.core.FileInfo;
import org.dromara.x.file.storage.core.FileStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class FileDetailController {
    @Autowired
    private FileStorageService fileStorageService;

    @PostMapping("/landlord/uploadLandlord")
    public String uploadLandlord(MultipartFile file) {
        String fileName = file.getOriginalFilename();
        System.out.println("fileName:"+fileName);
        FileInfo fileInfo = fileStorageService.of(file)
                .setPath("Avatar/landlord/")
                .setSaveFilename("fileName.jpg")
                .upload();
        return fileInfo == null ? "上传失败！" : fileInfo.getUrl();
    }

    @PostMapping("/tenant/uploadTenant")
    public String uploadTenant(MultipartFile file) {
        String fileName = file.getOriginalFilename();
        FileInfo fileInfo = fileStorageService.of(file)
                .setPath("Avatar/landlord/")
                .setSaveFilename("fileName.jpg")
                .upload();
        return fileInfo == null ? "上传失败！" : fileInfo.getUrl();
    }
}
